<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>健康医疗</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="shortcut icon" href="../img/favicon.ico"/>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../element-ui/index.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/font-awesome/css/font-awesome.min.css">
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }

        .checkScrol::-webkit-scrollbar {
            display: none;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>检查组管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item>首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>检查组管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="编码/名称/助记码" v-model="queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleCurrentChange(1)" clearable>
                </el-input>
                <el-button @click="handleCurrentChange(1)" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="code" label="检查组编码" align="center"></el-table-column>
                <el-table-column prop="name" label="检查组名称" align="center"></el-table-column>
                <el-table-column label="适用性别" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="helpCode" label="助记码" align="center"></el-table-column>
                <el-table-column prop="remark" label="说明" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row.id)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination class="pagiantion"
                               :current-page="pageNow"
                               :page-size="pageSize"
                               :total="total"
                               layout="total, prev, pager, next, jumper"
                               @current-change="handleCurrentChange">
                </el-pagination>
            </div>
            <!-- 新增标签弹出层 -->
            <div class="add-form">
                <el-dialog title="新增检查组" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddForm" :model="formData" :rules="rules"
                                         label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="编码" prop="code">
                                                <el-input v-model="formData.code"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="名称" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="适用性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="不限" value="0"></el-option>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="助记码">
                                                <el-input v-model="formData.helpCode"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="说明">
                                                <el-input v-model="formData.remark" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="注意事项">
                                                <el-input v-model="formData.attention"
                                                          type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="检查项信息" name="second">
                                <div class="checkScrol">
                                    <div class="filter-container">
                                        <el-input v-model="queryCheckItem" placeholder="项目编码/项目名称"
                                                  style="width: 200px;"
                                                  class="filter-item" @keyup.enter.native="handleCheckItem"
                                                  clearable>
                                        </el-input>
                                        <el-button @click="handleCheckItem" class="dalfBut">查询</el-button>
                                    </div>
                                    <el-table ref="add-multipleTable" size="small" current-row-key="id"
                                              :data="tableData" stripe
                                              height="200px" row-key="id"
                                              @selection-change="handleSelectionChange">
                                        <el-table-column type="selection"
                                                         :reserve-selection="true"></el-table-column>
                                        <el-table-column prop="code" label="项目编码"
                                                         align="center"></el-table-column>
                                        <el-table-column prop="name" label="项目名称"
                                                         align="center"></el-table-column>
                                        <el-table-column prop="remark" label="项目说明"
                                                         align="center"></el-table-column>
                                    </el-table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹出层 -->
            <div class="add-form">
                <el-dialog title="编辑检查组" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataEditForm" :model="formData" :rules="rules"
                                         label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="编码" prop="code">
                                                <el-input v-model="formData.code"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="名称" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="适用性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="不限" value="0"></el-option>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="助记码">
                                                <el-input v-model="formData.helpCode"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="说明">
                                                <el-input v-model="formData.remark" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="注意事项">
                                                <el-input v-model="formData.attention"
                                                          type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="检查项信息" name="second">
                                <div class="checkScrol">
                                    <div class="filter-container">
                                        <el-input v-model="queryCheckItem" placeholder="项目编码/项目名称"
                                                  style="width: 200px;"
                                                  class="filter-item" @keyup.enter.native="handleCheckItem"
                                                  clearable>
                                        </el-input>
                                        <el-button @click="handleCheckItem" class="dalfBut">查询</el-button>
                                    </div>
                                    <el-table ref="edit-multipleTable" size="small" current-row-key="id"
                                              :data="tableData" stripe
                                              height="200px" row-key="id"
                                              @selection-change="handleSelectionChange">
                                        <el-table-column type="selection"
                                                         :reserve-selection="true"></el-table-column>
                                        <el-table-column prop="code" label="项目编码"
                                                         align="center"></el-table-column>
                                        <el-table-column prop="name" label="项目名称"
                                                         align="center"></el-table-column>
                                        <el-table-column prop="remark" label="项目说明"
                                                         align="center"></el-table-column>
                                    </el-table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/axios.min.js"></script>
<script src="../element-ui/index.js"></script>
<script type="text/javascript" src="../js/jquery-3.5.1.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pageNow: 1,//当前页码
            pageSize: 8,//每页显示的记录数
            total: 0,//总记录数
            queryString: "",//查询条件-检查组
            queryCheckItem: "",//查询条件-检查项
            activeName: 'first',//添加/编辑窗口Tab标签名称
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            checkitemIds: [],//新增和编辑表单中检查项对应的复选框
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                code: [{required: true, message: '编码为必填项', trigger: 'blur'}],
                name: [{required: true, message: '名称为必填项', trigger: 'blur'}]
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            //编辑的提交
            handleEdit() {
                this.$refs["dataEditForm"].validate((valid) => {
                    //表单校验通过
                    if (valid) {
                        //打开全屏遮罩
                        var fullscreenLoading = this.$loading();

                        //提交
                        var url = "../checkGroup/update?checkItemIds=" + this.checkitemIds;
                        axios.post(url, this.formData)
                            .then(res => {
                                if (res.data.flag) {
                                    this.$message.success(res.data.msg);
                                    //关闭编辑窗口
                                    this.dialogFormVisible4Edit = false;
                                    //刷新列表
                                    this.findPage();
                                } else {
                                    this.$message.warning(res.data.msg);
                                }

                                //关闭全屏遮罩
                                fullscreenLoading.close();
                            })
                            .catch(error => {
                                this.$message.error("请求出错：" + error);
                                //关闭全屏遮罩
                                fullscreenLoading.close();
                            });
                    }
                });
            },
            //复选框变化
            handleSelectionChange(arr) {
                //获取id
                this.checkitemIds = [];
                arr.forEach(el => {
                    this.checkitemIds.push(el.id);
                });
            },
            //加载检查项
            handleCheckItem(flag, id) {
                //打开全屏遮罩
                var fullscreenLoading = this.$loading();

                var url = "../checkItem/findByQuery?query=" + this.queryCheckItem;
                axios.get(url)
                    .then(res => {
                        if (res.data.flag) {
                            this.tableData = res.data.data;

                            if (flag === 0) {
                                //通过新增按钮打开面板时，清空选中状态
                                this.$refs["add-multipleTable"].clearSelection();
                            } else if (flag === 1) {
                                //通过编辑按钮打开面板时，清空选中状态，并加载检查组关联的检查项ID
                                this.$refs["edit-multipleTable"].clearSelection();
                                this.handleCheckItemIds(id);
                            }
                        } else {
                            this.$message.warning(res.data.msg);
                        }

                        //关闭全屏遮罩
                        fullscreenLoading.close();
                    })
                    .catch(error => {
                        this.$message.error("请求出错：" + error);
                        //关闭全屏遮罩
                        fullscreenLoading.close();
                    });
            },
            //添加
            handleAdd() {
                this.$refs["dataAddForm"].validate(valid => {
                    //表单校验通过
                    if (valid) {
                        //打开全屏遮罩
                        var fullscreenLoading = this.$loading();

                        //提交
                        var url = "../checkGroup/add?checkItemIds=" + this.checkitemIds;
                        axios.post(url, this.formData)
                            .then(res => {
                                if (res.data.flag) {
                                    this.$message.success(res.data.msg);
                                    //关闭新增窗口
                                    this.dialogFormVisible = false;
                                    //刷新列表
                                    this.findPage();
                                } else {
                                    this.$message.warning(res.data.msg);
                                }

                                //关闭全屏遮罩
                                fullscreenLoading.close();
                            })
                            .catch(error => {
                                this.$message.error("请求出错：" + error);
                                //关闭全屏遮罩
                                fullscreenLoading.close();
                            });
                    }
                });
            },
            //分页查询
            findPage() {
                //打开全屏遮罩
                var fullscreenLoading = this.$loading();

                var url = "../checkGroup/findPage/" + this.pageNow + "/" + this.pageSize
                    + "?query=" + this.queryString;
                axios.get(url)
                    .then(res => {
                        if (res.data.flag) {
                            // 分页的结果
                            this.dataList = res.data.data.rows;
                            // 总记录
                            this.total = res.data.data.total;
                        } else {
                            this.$message.warning(res.data.msg);
                        }

                        //关闭全屏遮罩
                        fullscreenLoading.close();
                    })
                    .catch(error => {
                        this.$message.error("请求出错：" + error);
                        //关闭全屏遮罩
                        fullscreenLoading.close();
                    });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.checkitemIds = [];
                this.queryCheckItem = "";
                // 默认选中基本信息标签页
                this.activeName = 'first';
            },
            // 弹出添加窗口
            handleCreate() {
                //重置表单数据
                this.resetForm();
                //弹出新增窗口
                this.dialogFormVisible = true;
                //加载检查项列表
                this.handleCheckItem(0);
            },
            // 弹出编辑窗口
            handleUpdate(id) {
                //重置表单，弹出编辑窗口
                this.resetForm();
                this.dialogFormVisible4Edit = true;
                //加载被编辑的检查组
                this.handleCheckGroup(id);
                //加载检查项列表
                this.handleCheckItem(1, id);
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pageNow = currentPage;
                this.findPage();
            },
            //加载检查组关联的检查项ID
            handleCheckItemIds(id) {
                //打开全屏遮罩
                var fullscreenLoading = this.$loading();
                //通过id查询检查组
                axios.get('../checkGroup/findCheckItemIds/' + id)
                    .then(res => {
                        if (res.data.flag) {
                            this.checkitemIds = res.data.data;

                            //回显检查组关联的检查项
                            this.checkitemIds.forEach(checkItemId => {
                                for (var i = 0; i < this.tableData.length; i++) {
                                    var checkItem = this.tableData[i];
                                    if (checkItemId == checkItem.id) {
                                        this.$refs["edit-multipleTable"].toggleRowSelection(this.tableData[i], true);
                                    }
                                }
                            });
                        } else {
                            this.$message.warning(res.data.msg);
                        }

                        //关闭全屏遮罩
                        fullscreenLoading.close();
                    })
                    .catch(error => {
                        this.$message.error("请求出错：" + error);
                        //关闭全屏遮罩
                        fullscreenLoading.close();
                    });
            },
            //加载被编辑的检查组
            handleCheckGroup(id) {
                //打开全屏遮罩
                var fullscreenLoading = this.$loading();
                //通过id查询检查组
                axios.get('../checkGroup/findById/' + id)
                    .then(res => {
                        if (res.data.flag) {
                            this.formData = res.data.data;
                        } else {
                            this.$message.warning(res.data.msg);
                        }

                        //关闭全屏遮罩
                        fullscreenLoading.close();
                    })
                    .catch(error => {
                        this.$message.error("请求出错：" + error);
                        //关闭全屏遮罩
                        fullscreenLoading.close();
                    });
            },
            // 删除
            handleDelete(id) {
                this.$confirm('此操作将【永久删除】该检查组, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //打开全屏遮罩
                    var fullscreenLoading = this.$loading();

                    // 提交删除
                    axios.delete("../checkGroup/deleteById/" + id)
                        .then(res => {
                            if (res.data.flag) {
                                this.$message.success(res.data.msg);
                                //刷新列表
                                this.findPage();
                            } else {
                                this.$message.warning(res.data.msg);
                            }

                            //关闭全屏遮罩
                            fullscreenLoading.close();
                        })
                        .catch(error => {
                            this.$message.error("请求出错：" + error);
                            //关闭全屏遮罩
                            fullscreenLoading.close();
                        });
                }).catch(() => {
                });
            }
        }
    })
</script>
</html>
